-- 2012-05-17 EM .

alter procedure sp_get_special_rights
	@Phone varchar(21),
	@logon varchar(50) output,
	@identificator_id bigint output,
	@Result varchar(160) output
as
begin
	set nocount on;
	
exec sms_p.dbo.prints 'GSR 000','sp_get_special_rights:', @Phone,32

	
	declare @uid bigint set @uid = null;
	

select @identificator_id=i.id, @uid = u.id, @logon=i.code_b from dbdata.dbo.identificators as i
		join dbdata.dbo.users as u on u.id=i.uid
		join dbdata.dbo.phones as p on p.uid=u.id
		where p.phone = @Phone  and i.[enabled]=1 and i.dt_removed is null and u.dt_locked is null and p.enabled=1 and p.dt_removed is null

exec sms_p.dbo.prints 'GSR 023','identificator id:',@identificator_id,32
exec sms_p.dbo.prints 'GSR 024','user id:', @uid,32
exec sms_p.dbo.prints 'GSR 025','logon', @Logon,32

	
if @identificator_id is  null
		begin
		set @Result='Uknown identificator'
		exec sms_p.dbo.prints 'GSR 031','Error', @Result,32
		return
		end







end;
go

grant execute on sp_get_special_rights to Executer;